package com.lap.auth.adapter.driving.persistence.menu;

import java.util.List;

import com.lap.auth.adapter.driving.persistence.menu.po.MenuPo;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import com.lap.auth.domain.menu.Menu;
import com.lap.auth.domain.menu.MenuType;
import com.lap.framework.tools.EnumUtil;

@Mapper(componentModel = "spring")
public interface MenuConverter {

  @InheritInverseConfiguration
  MenuPo toPo(Menu menu);

  @Mapping(target = "meta.title", source = "title")
  @Mapping(target = "meta.icon", source = "icon")
  @Mapping(target = "meta.hide", source = "hide")
  @Mapping(target = "meta.keepAlive", source = "keepAlive")
  @Mapping(target = "meta.affix", source = "affix")
  @Mapping(target = "meta.iframe", source = "iframe")
  @Mapping(target = "event", ignore = true)
  Menu toDomain(MenuPo menuPo);

  List<Menu> toDomains(List<MenuPo> list);

  default MenuType codeToMenuType(Integer code) {
    return EnumUtil.fromCode(MenuType.class, code);
  }

  default Integer menuTypeToCode(MenuType type) {
    return type.getCode();
  }
}
